﻿using System;
using System.Collections.Generic;
using System.Text;
using SistemaLib.sipe.db.sqlserver;
using SistemaLib.Entidades;
using SistemaLib.sipe.db.general;
using SistemaLib.sipe.util;
using System.Data;


namespace SistemaLib.Persistencia
{
    class DbTareaTipo : DbBase
    {

        private void Cargar(DataRow fila, TareaTipo obj)
        {
            obj.Id = ObtieneCampo.TipoInt(fila, "id");
            obj.Descripcion = ObtieneCampo.TipoInt(fila, "descripcion");
        }

        public TareaTipo CargarTareaTipo(int idTT)
        {
            TareaTipo obj = new TareaTipo();

            string sql = @"select * from TareasTipos where id = @id";

            DataSet ds;

            DbParameterCollection col = new DbParameterCollection();
            col.Add(DbConnection.SqlInputParam("@id", DbTipo.Entero, 0, idTT));

            this.DbConnection.RunDataSetProcedure(sql, col, CommandType.Text, out ds);

            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                DataRow fila = ds.Tables[0].Rows[0];
                Cargar(fila, obj);
            }

            return obj;
        }

        public DataSet ListarTareaTipos()
        {
            string sql = @"select * from TareasTipos order by id";

            DataSet ds;

            this.DbConnection.RunDataSetProcedure(sql, CommandType.Text, out ds);

            return ds;
        }  

    }
}
